package com.soul.base.jvm.serialize;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

/**
 * @author gin
 * @date 2021/4/25
 */
public class SerializeObjTest {

    public static void main(String[] args) {
        try {
            SerializeObj obj = new SerializeObj();
            obj.setAge(29);
            obj.setUserName("fankai");
            //可以看到只有属性被序列化, 方法不会被序列化
            //因序列化数据的接收方应能load对应的class
            FileOutputStream fos = new FileOutputStream("D:\\var\\SerializeObj");
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(obj);
            oos.close();
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
